#ifndef OFXIRCCONNECTIONH
#define OFXIRCCONNECTIONH

#include <string>
#include <vector>
#include "ofxNetwork.h"
#include "ofxIRCChannel.h"
#include "ofxIRCMessageFactory.h"
#include "ofxIRCLineBuffer.h"

class ofxIRCUser;
class ofxIRCMessageType;

class ofxIRCConnection {
	public:
		ofxIRCConnection(std::string sServer, int nPort, ofxIRCUser* oUser);
		void connect();
		void update();
		void addChannel(ofxIRCChannel oChannel);

		bool hasMessages();
		void clearMessages();
		std::vector<ofxIRCMessageType*>getMessages();

		enum {
			 STATE_CONNECT
			,STATE_IDENTIFY
			,STATE_JOIN
			,STATE_RECIEVE
		};

	private:
		void joinChannels(); //join 'non' connected channels.
		void identify();
		void receive();


		std::string	server;
		int state;
		int port;
		std::vector<ofxIRCChannel> channels;
		std::vector<ofxIRCMessageType*> messages;
		ofxTCPClient tcp_client;
		ofxIRCUser* user;
		ofxIRCLineBuffer buffer;
		ofxIRCMessageFactory factory;
};
#endif
